<%!
from mysite.util.security import get_ck
%>

<%def name='a_auth(href="javascript:void(0)",className=None,**kwds)' filter="trim">
<%
if not request.user:
    kwds["onclick"] = "return pop_win.load('/js/pop_win/login')"
    href = "/login"
attr=[("href",href)]
if className:
    attr.append(("class",className))
attr.extend(kwds.items())
attr = " ".join([
    '%s="%s"'%(i[0],i[1].replace('"','\\"'))
    for i in attr
])
%>
<a ${attr|n}>${caller.body()|n}</a>
</%def>

<%def name="a_ck(href,*args,**kwds)" filter="trim">
<%
if request.user:
    meta = (href,get_ck())
    if href.find('?')<0:
        href = "%s?ck=%s"
    else:
        href = "%s&ck=%s"
    href=href%meta
%>
<%call expr="a_auth(href,*args,**kwds)">${caller.body()|n}</%call>
</%def>


<%def name='form(method="POST",className=None,**kwds)' filter="trim">
<%
attr=[("method",method)]
if className:
    attr.append(("class",className))
attr.extend(kwds.items())
attr = " ".join([
    '%s="%s"'%(i[0],i[1].replace('"','\\"'))
    for i in attr
])
%>
<form ${attr|n}>\
${caller.body()|n}\
<input type="hidden" value="${get_ck()}" name="ck">\
</form>
</%def>

<%def name="error_tip(error,n)">
    <% 
if error:
    tip = error[n]
else:
    tip = ""
    %>
    <span class="Err" id="err_${n}" \
    %if tip:
    style="display:block"\
    %endif
    >
    ${tip|n}\
    </span>
</%def>
